import pandas as pd
from matplotlib import pyplot as plt
from collections import Counter

raw_dataset = pd.read_csv('../data/dataset-bia-day-i-cut-undummy.csv')
day1 = 68
day2 = 157
day3 = 129
day4 = 70
day1_data = raw_dataset[raw_dataset['label'] == 1]
day2_data = raw_dataset[raw_dataset['label'] == 2]
day3_data = raw_dataset[raw_dataset['label'] == 3]
day4_data = raw_dataset[raw_dataset['label'] == 4]

feature = 'hxb'
# # %
# for item in raw_dataset[feature].unique().tolist():
#
#     data = raw_dataset[raw_dataset[feature] == item]
#     print(
#         item,
#         len(data), round(len(data)/424, 4),
#         len(data[data['label'] == 1]), round(len(data[data['label'] == 1]) / day1, 4),
#         len(data[data['label'] == 2]), round(len(data[data['label'] == 2]) / day2, 4),
#         len(data[data['label'] == 3]), round(len(data[data['label'] == 3]) / day3, 4),
#         len(data[data['label'] == 4]), round(len(data[data['label'] == 4]) / day4, 4),
#     )

# median[IQR]
day_list = round(raw_dataset[feature].quantile([0.25, 0.5, 0.75]), 2).values.tolist()
day1_list = round(day1_data[feature].quantile([0.25, 0.5, 0.75]), 2).values.tolist()
day2_list = round(day2_data[feature].quantile([0.25, 0.5, 0.75]), 2).values.tolist()
day3_list = round(day3_data[feature].quantile([0.25, 0.5, 0.75]), 2).values.tolist()
day4_list = round(day4_data[feature].quantile([0.25, 0.5, 0.75]), 2).values.tolist()
print(str(day_list[1])+"["+str(day_list[0])+", "+str(day_list[2])+"]")
print(str(day1_list[1])+"["+str(day1_list[0])+", "+str(day1_list[2])+"]")
print(str(day2_list[1])+"["+str(day2_list[0])+", "+str(day2_list[2])+"]")
print(str(day3_list[1])+"["+str(day3_list[0])+", "+str(day3_list[2])+"]")
print(str(day4_list[1])+"["+str(day4_list[0])+", "+str(day4_list[2])+"]")



# # mean[sd]
# print(round(raw_dataset[feature].mean(), 2), round(raw_dataset[feature].std(), 2))
# print(round(day1_data[feature].mean(), 2), round(day1_data[feature].std(), 2))
# print(round(day2_data[feature].mean(), 2), round(day2_data[feature].std(), 2))
# print(round(day3_data[feature].mean(), 2), round(day3_data[feature].std(), 2))
# print(round(day4_data[feature].mean(), 2), round(day4_data[feature].std(), 2))


categories = [
    'zd',
    'gender',
    'bmij',
    'nation',
    'j',
    'surgery',
    'chemotherapy',
    'targeted_drugs',
    'radiotherapy',
    'drugs',
    'food',
    'kenel',
    'fuzhang',
    'bsn',
    'gzy',
    'xr',
    'cdbb',
    'cdzb',
    'db',
    'bp',
    'ssfs',
    'fhfs',
    'icu',
    'bowelsound'
]

continues = [
    'age',
    'height',
    'weight',
    'index',
    'score',
    'time',
    'feces',
    'nrs_score',
    'changminyinyoushang',
    'changminyinzuoshang',
    'changminyinyouxia',
    'changminyinzuoxia',
    'wexner',
    'vaizey',
    'hb',
    'rbc',
    'wbc',
    'palb',
    'tp',
    'alb',
    'neut',
    'urea',
    'crea',
    'ua',
    'glu',
    'k',
    'na',
    'cl',
    'ca',
    'qcxr',
    'hr',
    'scxyssy',
    'scxyszy',
    'dxl',
    'mlpf',
    'xl',
    'xyss',
    'xysz',
    'mzsj',
    'cgsj',
    'qxsj',
    'sssj',
    'cxl',
    'xbl',
    'jtl',
    'jtry',
    'cdcd',
    'fqzs',
    'pqzs',
    'yy',
    'qcxl', 'qcxy', 'qcszy', 'spo', 'jcdxl', 'nrspf', 'ljsy', 'sy', 'ywjl', 'xhdb', 'hxb', 'bxb', 'qbdb', 'zdb', 'bdb',
    'zxlxb', 'cmz', 'nsz', 'jgz', 'ns', 'pttz', 'jia', 'naz', 'lz', 'gz', 'syzl', 'znl', 'ysl', 'cnznl', 'cnwznl',
    'ysxx', 'zsxx', 'yxxx', 'zxxx', 'jjmlpf',
]

# # 数值特征
# for feature in continues:
#     # Creating an empty chart
#     fig, ((ax1, ax2)) = plt.subplots(1, 2, figsize=(6, 5))
#
#     # Extracting the feature values
#     x = raw_dataset[feature].values
#
#     # Boxplot
#     ax1.boxplot(x)
#     ax1.set_title('Boxplot for {}'.format(feature))
#
#     # Histogram
#     n, bins, patches = ax2.hist(x, bins=4, edgecolor='black')
#     ax2.set_title('Histogram for {}'.format(feature))
#     ax2.set_xticks(bins)
#     ax2.set_xticklabels(bins, rotation=45)
#     ax2.grid(linestyle="-", alpha=0.3)
#
#     # Display
#     plt.savefig('png/continues/{}.png'.format(feature))
#     plt.show()
# #
# # 分类特征
# for feature in categories:
#     # Creating an empty chart
#     fig, ax = plt.subplots(figsize=(6, 5))
#
#     # Extracting the feature values
#     x = raw_dataset[feature].values
#
#     # Counting the number of occurrences for each category
#     data = Counter(x)
#     category = list(data.keys())
#     counts = list(data.values())
#     counts_per = ["{}%".format(round(x/4.24, 2)) for x in counts]
#
#     # Boxplot
#     bar = ax.bar(category, counts)
#     ax.bar_label(bar, counts, padding=3)
#     ax.bar_label(bar, counts_per, label_type='center')
#
#     # Display
#     plt.title('Barchart for {}'.format(feature))
#     plt.savefig('png/categories/{}.png'.format(feature))
#     plt.show()
#
# # 标签
# # Creating an empty chart
# fig, ((ax1, ax2)) = plt.subplots(1, 2, figsize=(10, 4))
#
# # Counting the number of occurrences for each category
# data = Counter(raw_dataset['event'].replace({0: 'not happen yet', 1: 'happen'}))
# category = list(data.keys())
# counts = list(data.values())
# idx = range(len(counts))
#
# # Displaying the occurrences of the event/censoring
# ax1.bar(idx, counts)
# ax1.set_xticks(idx)
# ax1.set_xticklabels(category)
# ax1.set_title('Occurences of the event/censoring', fontsize=15)
#
# # Showing the histogram of the survival times for the censoring
# time_0 = raw_dataset.loc[raw_dataset['event'] == 0, 'label']
# ax2.hist(time_0, bins=30, alpha=0.3, color='blue', label='not happen yet')
#
# # Showing the histogram of the survival times for the events
# time_1 = raw_dataset.loc[raw_dataset['event'] == 1, 'label']
# ax2.hist(time_1, bins=20, alpha=0.7, color='black', label='happen')
# ax2.set_title('Histogram - survival time', fontsize=15)
#
# # Displaying everything side-by-side
# plt.legend(fontsize=10)
# plt.savefig('png/label/label.png')
# plt.show()
